#include <UnitTest++.h>
#include "../job.h"
#include <iostream>
#include <string>
#include "../option.h"
#include "../MyMap.h"

using namespace std;

TEST(OptionClassPassAlways)
{
    CHECK(true);
}

TEST(OptionClassCreation)
{
	option opt;
	CHECK_EQUAL(-1, opt.NIDAQConstants["terminalmode"][0]);
	CHECK_EQUAL(DAQmx_Val_RSE, opt.NIDAQConstants["terminalmode"][1]);
}

TEST(OptionClassLoadDirectly)
{
	option opt;
	long tmNum = 2, ml=3;
	opt.L["messagelevel"] = ml;
	opt.L["terminalmode"] = 2;
	CHECK(opt.NIDAQConstants["terminalmode"][tmNum] != opt.L["terminalmode"]);	
	opt.getNIDAQConstants();
	CHECK_EQUAL(ml, opt.L["messagelevel"]);
	CHECK_EQUAL(opt.NIDAQConstants["terminalmode"][tmNum], opt.L["terminalmode"]);	
}

TEST(OptionClassLoadFromStringUsingMyMapClass)
{
	// these strings came from TestThroughPackage.nb don'tforget trailing semicolon
	string sLong ="numchannels 1;samples 50;terminalmode 3;units 0;"
						"messagelevel 1;activeedge 0;setuponly 0;"
						"samplemode 0;transfermech 1;";
	string sDouble= "frequency 100.0;min -10.0;max 10.0;timeout 10.0;";
	string sString = "channels dev1/ai0;clock OnboardClock;";

	option opt;
	opt.L = MyMap<long>(sLong);
	opt.D = MyMap<double>(sDouble);
	opt.S = MyMap<string>(sString);
	opt.getNIDAQConstants();
	CHECK_EQUAL(1, opt.L["messagelevel"]);
	CHECK_EQUAL(opt.NIDAQConstants["terminalmode"][3], opt.L["terminalmode"]);
	CHECK_CLOSE(100.0, opt.D["frequency"],1e-10);
	CHECK_EQUAL("dev1/ai0", opt.S["channels"]);
//	cout << opt.toString() << endl;
}

TEST(OptionClassCreateFromString)
{
	std::string s = "hello";	
//	option opt(optionsFromString(s));
	option opt = optionsFromString(s);			// temporary to copyconstructor
	CHECK_EQUAL(-1, opt.NIDAQConstants["terminalmode"][0]);
	CHECK_EQUAL(DAQmx_Val_RSE, opt.NIDAQConstants["terminalmode"][1]);
	CHECK_EQUAL(opt.S[s], "just a quick test");
}
	
